import router from '@/router'
const getDefaultState = () => {
  return {
    token: '',
    userInfo: {}
  }
}

const state = getDefaultState()

const mutations = {
  SET_TOKEN: (state, token) => {
    state.token = token
  },
  LOGOUT: (state) => {
    state.token = ''
    state.userInfo = ''
    router.push('/login?redirect=' + location.href.split('#')[1])
  },
  SET_USER_INFO: (state, userInfo = {}) => {
    state.userInfo = userInfo
  }
}

const actions = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
